import {ERR_OK} from '@/utils/commons'

//  普通返回
interface ResponseData<T = never> {
  Code: number;
  ErrorCode: string;
  Result: T;
  Message: string;
}

//  分页返回
export interface PageResData<E = object> {
  CheckList?: any;
  CurrentPage: number;
  Items: E[];
  TotalNum: number;
  TotalPageCount: number;
}

//  分页参数

const isSuccessRes = <T = any>(res: ResponseData<T>): boolean => {
  const {Code} = res;
  return Code === ERR_OK;
};


const getOriginPic = (compressUrl: string) => compressUrl.slice(0, -12)

export const findByIdFactory = (data) => (id): { label: any, value: any } => {
  return data?.find(v => v.value === id) ?? ({} as any)
}


export const ADD_ITEM_FLAG = 'ADD_ITEM_FLAG'

export const isAddItem = (id) => id === ADD_ITEM_FLAG

export {ResponseData, isSuccessRes, getOriginPic}
